package cn.mcsys.platform.core.web;

import cn.mcsys.myadmin.common.utils.DateUtils;
import cn.mcsys.myadmin.common.web.JsonResult;
import cn.mcsys.myadmin.dubbo.service.BackService;
import cn.mcsys.myadmin.modules.air.entity.AirCarSumRecord;
import cn.mcsys.myadmin.modules.platform.entity.AirVehicleGpsBus;
import cn.mcsys.platform.core.service.PlatformService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author bobo
 * @create 2018-10-06 15:52
 * @desc ${DESCRIPTION}
 **/
@Controller
public class TestController {
    private static Logger logger = LoggerFactory.getLogger(IndexController.class);

    @Autowired
    private BackService backService;

    @Autowired
    private PlatformService platformService;
    @GetMapping("test")
    @ResponseBody
    public JsonResult test2(HttpServletRequest request) {
        System.out.println("test" + request.getRequestURI());
        Date currentDate = new Date();
        Date beforeDate = DateUtils.addSeconds(currentDate, -20);
        List<AirVehicleGpsBus> busGps = backService.getBusGps(currentDate, beforeDate);
        for (AirVehicleGpsBus busGp : busGps) {
//            busGp.setLon(String.valueOf(togcj02[0]));
//            busGp.setLat(String.valueOf(togcj02[1]));
        }
        return JsonResult.success(busGps);
    }

    @GetMapping("testAdd")
    @ResponseBody
    public JsonResult testAdd() {
        Date date = DateUtils.parseDate("2018-11-11 07:00:00");
        for (int i = 0; i < 27; i++) {
            AirCarSumRecord record = new AirCarSumRecord();
            record.setCarType(1);
            record.setCarSum(32+i);
            record.setRecordDate(date);
            backService.saveAirCarSumRecord(record);
            date = DateUtils.getDateAfterMinutes(date, 30);
        }
        return JsonResult.success();
    }

    @GetMapping("test2")
    @ResponseBody
    public JsonResult test() {
        System.out.println("test2.do");
        Date date1 = DateUtils.parseDate("2018-11-09");
        Date date2 = DateUtils.parseDate("2018-11-10");
        Date date3 = DateUtils.parseDate("2018-11-11");
        List<AirCarSumRecord> recordList1 = backService.getSumRecordWithTime(date1);
        List<AirCarSumRecord> recordList2 = backService.getSumRecordWithTime(date2);
        List<AirCarSumRecord> recordList3 = backService.getSumRecordWithTime(date3);
        Map<String,Object> result = new HashMap<>();
        result.put("recordList1",recordList1);
        result.put("recordList2",recordList2);
        result.put("recordList3",recordList3);
        return JsonResult.success(result);
    }
}
